package models

import (
	"fmt"
	"gorm.io/gorm"
)

type Hospital struct { //定义医院挂号结构体
	gorm.Model
	Img   string  `json:"img" gorm:"type:varchar(60)"`   //头像
	Name  string  `json:"name" gorm:"type:varchar(30)"`  //患者名称
	Tel   string  `json:"tel" gorm:"type:varchar(50)"`   //患者手机号
	Where string  `json:"where" gorm:"type:varchar(50)"` //挂号科室
	Money float64 `json:"money" gorm:"type:float(10,2)"` //挂号费
	Start string  `json:"start" gorm:"type:varchar(60)"` //挂号时间
}

func List(page int, pageSize int) (int64, []Hospital, error) {
	var sum int64
	err = DB.Model(&Hospital{}).Count(&sum).Error
	if err != nil {
		fmt.Println("总条数获取失败")
		return 0, nil, err
	}
	offset := (page - 1) * pageSize
	var hospital []Hospital
	err = DB.Model(&Hospital{}).Offset(offset).Limit(pageSize).Find(&hospital).Error
	if err != nil {
		return 0, nil, err
	} else {
		return sum, hospital, nil
	}
}
